package com.wzdigit.wms.raw.controller.asn;


import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.request.trsn.ScanGoodsSNNewRequest;
import com.wzdigit.wms.basic.client.request.trsn.ScanUpRequest;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.basic.domain.dtos.inventory.SnInforDto;
import com.wzdigit.wms.raw.constant.RawWareConstant;
import com.wzdigit.wms.raw.service.asn.TransferUpService;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;


/*

 * 收料上架PDA
 * Created by zyf on 2021/6/17 8:51
 *
*/


@RestController
@Api(tags = "收料上架PDA")
@RequestMapping(value = RawWareConstant.API_VERSION)
public class ScanUpController {

    private final String REQUEST_MODEL = "/ScanUp";

    @Autowired
    private TransferUpService transferUpService;


    @ApiOperation(value = "扫描条码", notes = "扫描条码")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/getgoodsinfoNew")
    public List<SnInforDto> getgoodsinfoNew(ScanGoodsSNNewRequest search, HttpServletRequest servletRequest,
                                            HttpServletResponse servletResponse) {
        try {
            return transferUpService.scanGoodsSNNew(search);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "扫描库位上架", notes = "扫描库位上架")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @PostMapping(value = REQUEST_MODEL + "/scanUp")
    public Result<?> scanUp(@Valid @RequestBody ScanUpRequest dto, HttpServletRequest servletRequest,
                            HttpServletResponse servletResponse) throws Exception {
        try {
            return transferUpService.scanUp(dto, servletRequest);
        } catch (Exception ex) {
            ex.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }


//    @Autowired
//    private ScanUpService scanUpService;

/*    @ApiOperation(value = "获取收料上架通知（分页）", notes = "获取收料上架通知（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/SearchNotice", method = RequestMethod.GET)
    public PagerInfo<List<ScanUpNoticeResponse>> searchAsnTrsnReport(
            String filter, Pager<?> pager, Integer searchFlag,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return scanUpService.searchScanUpNotice(filter,searchFlag,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "主页跳转扫码页面【请求缓存】", notes = "主页跳转扫码页面【请求缓存】")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/scanCacheInfo/{asnNo}/{skuCode}", method = RequestMethod.GET)
    public ScanUpCommitRequest scanCacheInfo(
            @PathVariable("asnNo") String asnNo, @PathVariable("skuCode") String skuCode,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return scanUpService.scanCacheInfo(asnNo,skuCode);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "扫描序号", notes = "扫描序号")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/ScanSn", method = RequestMethod.GET)
    public ScanUpCommitRequest scanUpSn(
            ScanUpSnRequest request,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return scanUpService.scanSn(request);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "清除SN", notes = "清除SN")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/ClearSn", method = RequestMethod.POST)
    public ScanUpCommitRequest clearSn(
            @RequestBody ClearSnRequest request,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return scanUpService.clearSn(request);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "扫描库位", notes = "扫描库位")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/ScanLoc", method = RequestMethod.POST)
    public Boolean scanLoc(
            @RequestBody ScanLocRequest request,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return scanUpService.scanLoc(request,servletRequest);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "上架提交", notes = "上架提交")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/Commit", method = RequestMethod.POST)
    public Result<?> scanUpCommit (
            @RequestBody ScanUpCommitRequest request,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try{
            return scanUpService.scanUpCommit(request,servletRequest,servletResponse);
        }catch (Exception ex) {
            ex.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "删除缓存", notes = "删除缓存")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/delete/cache", method = RequestMethod.GET)
    public void deleteCachScan (
            String asnNo,String skuCode,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try{
            scanUpService.deleteCache(asnNo,skuCode);
        }catch (Exception ex) {
            ex.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }*/

}
